<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="./css/style.min.css">
    <title>个人中心</title>
</head>
<script type="text/javascript">
    window.onload=function () {
            document.addEventListener('touchstart',function (event) {
                if(event.touches.length>1){
                    event.preventDefault();
                }
            })
            var lastTouchEnd=0;
            document.addEventListener('touchend',function (event) {
                var now=(new Date()).getTime();
                if(now-lastTouchEnd<=300){
                    event.preventDefault();
                }
                lastTouchEnd=now;
            },false)
        }
</script>

<body>
    <div id="personal_center">
        <div class="t-container">
            <header class="cl" v-show="header.show">
                <div class="nav-bar cl" @click="goback">
                    <span class="goback arrow_l"></span>
                    <span class="page-name" v-cloak>{{user.shop_name}}会员店</span>
                </div>
            </header>
            <div class="t-main">
                <div class="t-header">
                    <div class="t-header-box">
                        <a :href="'personal-information.html?storeid=' + store_id">
                            <div class="t-head-portrait">
                                <img :src="user.headicon">
                            </div>
                            <div class="t-head-message">
                                <p v-cloak><span class="PerUsrname">{{user.name}}</span></p>
                                <p v-cloak>{{user.mobile}}</p>
                            </div>
                        </a>
                        <div class="t-head-account" >
                           <!--  <a :href="'personal-information.html?storeid=' + store_id">账户管理<i class="t-account-icons"></i></a> -->
                           <img v-bind:src="WechatCodeImg" v-cloak v-if="WechatCodeImg">
                        </div>
                        <p class="WechatCodeID" v-cloak v-if="WechatCodeID">公众号ID：{{WechatCodeID}}</p>
                    </div>
                                    </div>
                <div class="t-column">
                    <div class="t-column-title">
                        <p>订单管理</p>
                        <a :href="'my-order.html?storeid=' +store_id + '&status='">查看全部订单<i class="t-account-icons"></i></a>
                    </div>
                    <div class="t-column-content">
                        <ul>
                            <li>
                                <a :href="'my-order.html?storeid=' +store_id + '&status=10'">
                                    <span class="t-payment">
                            <span class="t-corner" v-if="order_status_num[0]>0" v-cloak>{{order_status_num[0]}}</span>
                                    </span>待付款
                                </a>
                            </li>
                            <li>
                                <a :href="'my-order.html?storeid=' +store_id + '&status=20'">
                                    <span class="t-deliver-goods">
                                        <span class="t-corner" v-if="order_status_num[1]>0" v-cloak>{{order_status_num[1]}}</span>
                                    </span>
                                    待发货
                                </a>
                            </li>
                            <li>
                                <a :href="'my-order.html?storeid=' +store_id + '&status=30'">
                                    <span class="t-receipt-goods">
                                          <span class="t-corner" v-if="order_status_num[2]>0" v-cloak>{{order_status_num[2]}}</span>
                                    </span>
                                    待收货
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="t-gap-box"></div>
                <div class="t-column">
                    <div class="t-column-title">
                        <p>我的优惠券</p>
                        <a :href="'c-my-coupon.html?storeid='+ store_id + '&status='">共
                        <span class="t-address-num" v-cloak>{{total}}</span>
                        张优惠券<i class="t-account-icons"></i>
                        </a>
                    </div>
                </div>
                <div class="t-gap-box"></div>
                <div class="t-column t-second-column">
                    <div class="t-column-title">
                        <p>我的关注</p>
                        <a :href="'my-attention.html?storeid='+store_id">查看更多关注<i class="t-account-icons"></i></a>
                    </div>
                    <div class="t-column-content">
                        <ul>
                            <li v-for="item in items">
                                <a @click="viewDetail(item.goods_id)">
                                    <div class="t-img-box">
                                        <div class="goods-img">
                                            <div class="soff-shelf" v-if="item.goods && item.goods.validateStatus != 1">已下架</div>
                                            <img :src="item.goods && item.goods.goods_img1" alt="">
                                        </div>
                                        <div class="goods-name">
                                            <p v-cloak>{{item.goods && item.goods.goods_name}}</p>
                                        </div>
                                        <div class="goods-price">
                                            <p v-cloak>￥{{item.goods && item.goods.min_price}}</p>
                                        </div>
                                    </div>
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="t-gap-box"></div>
                <div class="t-column">
                    <div class="t-column-title">
                        <p>我的地址</p>
                        <a :href="'address.html?storeid='+store_id">共创建<span class="t-address-num" v-cloak>{{user.addressCreateNum}}</span>个地址，还可创建<span class="t-address-num" v-cloak>{{user.addressCanCreateNum}}</span>个<i class="t-account-icons"></i></a>
                    </div>
                </div>
            </div>
        </div>
        <toast ref="toast"></toast>
        <div class="t-footer">
            <ul class="t-ul-box counts-ul-box">
                <li><a :href="home_link" class="t-home"><i class=""></i>首页</a></li>
                <li><a :href="cate_link" class="t-classification"><i class=""></i>分类</a></li>
                <li>
                    <a :href="coupon_link" class="t-coupon">
                        <!-- <span class="counts" v-cloak >{{count}}</span>  -->
                        <i class=""></i>
                        优惠券
                        </a>
                </li>
                <li><a :href="cart_link" class="t-shopping-cat"><span class="counts" v-cloak>{{cart_counts}}</span><i class=""></i>购物车</a></li>
                <li><a :href="mycenter_link" class="t-my-select"><i class=""></i>我的</a></li>
            </ul>
        </div>
    </div>
    <script src="./js/lib/vue.js"></script>
    <script src="http://static.jdhui.com/lib/vue-resource/1.2/vue-resource.js"></script>
    <script src="./js/min/config.min.js"></script>
    <script src="./js/min/common.min.js"></script>
    <script src="./js/min/component.min.js"></script>
    <script>
    </script>
    <script>
        var store_id = parseInt(APP.getQueryString("storeid"));
        var toast = new component.popup.toast();
        var mycenter = new Vue({
            el: '#personal_center',
            data: {
                items: [],
                order_status_num: [0, 0, 0],
                store_id: APP.getQueryString('storeid'),
                user: {
                    headicon: '',
                    name: '',
                    mobile: '',
                    addressCreateNum: 0,
                    addressCanCreateNum: 0,
                    shop_name: ''
                },
                header: {
                    show: !APP.iswechat()
                },
                cart_counts: "",
                member_id: '',
                total:'',
                dev:window.location.host,
                win_href:window.location.href,
                home_link:"home.html?storeid="+store_id,
                cate_link:"category.html?storeid="+store_id,
                coupon_link:"c-call-center.html?storeid="+store_id,
                cart_link:"cart.html?storeid="+store_id+"&version="+APP.version,
                mycenter_link:"personal-center.html?storeid="+store_id,
                WechatCodeImg:'',
                WechatCodeID:''
            },
            components: {
                'toast': toast
            },
            mounted: function() {
                APP.init(this, function() {
                    this.member_id = APP.getCookie('memberid');
                }.bind(this), function(arg) {
                    this.member_id = arg.body.data.member.member_id;
                }.bind(this));
                this.getData();
                console.log(this.member_id);
                console.log(this.dev);
            },
            methods: {
                viewDetail: function(gid) {
                    Vue.http.get(APIPHP + 'index.php?r=goods/index/check&storeid=' + this.store_id + '&id=' + gid, {
                        emulateJSON: true
                    }).then(function(_res) {
                        if (_res.body.error_code == 0) {
                            window.location.href = 'goods-detail.html?storeid=' + this.store_id + '&id=' + gid;
                        } else {
                            this.$refs.toast.show('该商品已下架');
                        }
                    }.bind(this));
                },
                goback: function() {
                    window.history.go(-1);
                },
                getData: function() {
                    Vue.http.get(APIPHP + 'index.php?r=member/mysub/index&pageSize=3&storeid=' + this.store_id).then(function(_res) {
                        if (_res.body.error_code == 200) {
                            this.items = _res.body.data[0];
                        }
                    }.bind(this));
                    Vue.http.get(APIPHP + 'index.php?r=member/u/index&storeid=' + this.store_id).then(function(_res) {
                        if (_res.body.error_code == 200) {
                            var _d = _res.body.data;
                            if (_d.avatar) {
                               this.user.headicon = _d.avatar; 
                            }else{
                                this.user.headicon="http://js.jdhui.com/asset/2.0/main/images/phot.png"
                            }
                            
                            
                            this.user.name = _d.name;
                            this.user.mobile = _d.mobile;
                            this.user.addressCreateNum = _d.addr_has_create;
                            this.user.addressCanCreateNum = _d.addr_can_create;
                            this.user.shop_name = _d.belong_shop_name;
                        } else if (_res.body.error_code == 400) {
                            this.$refs.toast.show(_res.body.msg);
                            setTimeout(function() {
                                window.location.href = "login.html?storeid=" + store_id;
                            }.bind(this), 2000)

                        }
                    }.bind(this));
                    Vue.http.get(APIJAVA + 'c/mobile/order/order-status-count?shopId=' + this.store_id, {}).then(function(_res) {
                        if (_res.body.code == 1) {
                            var re = _res.body.obj;
                            if (re["10"] && parseInt(re["10"]) > 0) {
                                this.$set(this.order_status_num, 0, re["10"]);
                            }
                            if (re["20"] && parseInt(re["20"]) > 0) {
                                this.$set(this.order_status_num, 1, re["20"]);
                            }
                            if (re["30"] && parseInt(re["30"]) > 0) {
                                this.$set(this.order_status_num, 2, re["30"]);
                            }
                        }
                    }.bind(this));
                    Vue.http.get(APIJAVA + 'c/mobile/cart/count?shopId=' + this.store_id).then(function(_res) {
                        mycenter.cart_counts = _res.body.obj;
                    }, function(_res) {
                        console.log("err")
                    });
                    Vue.http.get(YHQJAVA + 'wap/receive/myTotal?shopId=' + this.store_id + '&memberId=' + this.member_id ).then(function(_res) {
                        mycenter.total = _res.body.obj.count;
                    }, function(_res) {
                        console.log("err")
                    });

                    //获取店铺二维码
                    Vue.http.jsonp(PHPHOST+'pcapi/member-shop/getmembershopinfo?shop_id=' + this.store_id
                    ).then(function(_res) {      
                    console.log(_res)            
                        if (_res.body.error_code == 0) {
                            var _re = _res.body.data;
                            if (_re.signal_img) {
                                this.WechatCodeImg = _re.signal_img;
                            }
                            if (_re.openid) {
                               this.WechatCodeID = _re.openid; 
                            }
                            
                        }
                    }.bind(this))
                }
            }
        })
    </script>
</body>

</html>